/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.utils;

import org.eclipse.jface.viewers.StructuredSelection;

import com.cea.papyrus.core.editpart.IUMLDiagramElementEditPart;
import com.cea.papyrus.core.editpart.IUMLElementEditPart;
import com.cea.papyrus.core.editpart.IUMLObjectEditPart;

/**
 * This class handles title label for tabbed properties.
 * 
 * @author Chokri Mraidha
 */
public class UMLObjectShortLabelProvider
extends UMLObjectLabelProvider {
	
	/**
	 * 
	 * 
	 * @param obj 
	 * 
	 * @return 
	 * 
	 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
	 */

	@Override
	public String getText(Object obj) {

		if ((obj == null) || obj.equals(StructuredSelection.EMPTY)) {
			return default_label;
		}

		Object object;		
		// Retrieve element or first element if multiple
		if (obj instanceof StructuredSelection) {
			object = ((StructuredSelection)obj).getFirstElement();
		} else {
			object = obj;
		}
		
		// Should be an IUMLObjectEditPart --> either IUMLDiagramElementEditPart || IUMLElementEditPart
		if (!(object instanceof IUMLObjectEditPart)) {
			return default_label;
		}

		String label = default_label;

		// Case IUMLDiagramElementEditPart
		if (object instanceof IUMLDiagramElementEditPart) {
			label	= ((IUMLDiagramElementEditPart) object).getDiagram().getName();
		} else if (object instanceof IUMLElementEditPart) {
			label	= getText((IUMLElementEditPart) object, true);
		}
		
		return label;
	}
}